<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>添加附属设备</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../../../css/global.css">
		<link rel="stylesheet" href="../../../../../css/style.css">
		<link rel="stylesheet" href="../../../../../css/mui.picker.css">
		<link rel="stylesheet" href="../../../../../css/mui.poppicker.css">
		<style>
			button:disabled {
				opacity: 1;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">添加附属设备</h1>
		</header>
		<div class="mui-content">
			<div class="details_con">
				<div hidden>
					<input type="hidden" id="ServiceNoticeId" />
					<input type="hidden" id="instrumentNo" />
					<input type="hidden" id="serviceNoV" />
				</div>
				<div class="clum">
					<span class="name">服务编号</span>
					<span id="serviceNo" class="txt"></span>
				</div>
				<div class="clum">
					<span class="name">附件名称<em class="t_red">*</em></span>
					<input type="text" id="assetName" class="d_ipt" value="" placeholder="请输入"/>
				</div>
				<div class="clum">
					<span class="name">附件序列号</span>
					<input type="text" id="assetSn" class="d_ipt" value="" placeholder="请输入"/>
				</div>
				<div class="clum">
					<span class="name">保修开始时间</span>
					<button id='assetWarrantyStart' type="button" class="selectDate">请选择保修开始时间</button>
				</div>
				<div class="clum">
					<span class="name">保修结束时间</span>
					<button id='assetWarrantyEnd' type="button" class="selectDate">请选择保修结束时间</button>
				</div>
				<div class="line"></div>
				<div class="btn_box">
					
					<span id="cancel" class="fl">取消</span>
					<span id="saveBtn" class="fr red">保存</span>
				</div>
				<div style="height: 50px;"></div>
			</div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../../../js/mui.min.js"></script>
		<script src="../../../../../js/utils/h.js"></script>
		<script src="../../../../../js/constant.js"></script>
		<script src="../../../../../js/common.js"></script>
		<script src="../../../../../js/utils/base64.js"></script>
		<script src="../../../../../js/utils/md5.js"></script>
		<script src="../../../../../js/utils/sortMap.js"></script>
		<script src="../../../../../js/utils/http.js"></script>
		<script src="../../../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../../../js/utils/rolldate.min.js"></script>
		<script src="../../../../../js/mui.picker.js"></script>
		<script src="../../../../../js/mui.poppicker.js"></script>
		<script type="text/javascript" charset="utf-8">

			(function($, doc) {
				$.init();

				// 取消方法
				h("#cancel").tap(function(){
					$.back()
				});

				$.plusReady(function() {
					var self = plus.webview.currentWebview();
					// 获取上一个页面传过来的参数并显示到页面
					h('#serviceNo').html(self.serviceNo);
					h('#serviceNoV').val(self.serviceNo);
					h('#ServiceNoticeId').val(self.ServiceNoticeId);
					h('#instrumentNo').val(self.instrumentNo);

					// 初始化时间控件 保修开始时间
					new Rolldate({
						el: '#assetWarrantyStart',
						format: 'YYYY-MM-DD hh:mm',
						beginYear: 2015,
						endYear: 2050,
						trigger: 'click',
						lang: {
							title: '请选择保修开始时间',
						},
						confirm: function(date) {
					
						}
					})
					// 初始化时间控件 保修结束时间
					new Rolldate({
						el: '#assetWarrantyEnd',
						format: 'YYYY-MM-DD hh:mm',
						beginYear: 2015,
						endYear: 2050,
						trigger: 'click',
						lang: {
							title: '请选择保修结束时间',
						},
						confirm: function(date) {
					
						}
					})

					// 保存草稿按钮触发事件
					h('#saveBtn').tap(function() {
						var assetName = h("#assetName").val();
						if(assetName==undefined || assetName==""){
							app.toast("请输入附件名称");
							return
						}
						var assetWarrantyStart = h("#assetWarrantyStart").html();
						var assetWarrantyEnd = h("#assetWarrantyEnd").html();
						if ((assetWarrantyStart == undefined || assetWarrantyStart == "" || assetWarrantyStart == '请选择保修开始时间')&&(assetWarrantyEnd == undefined || assetWarrantyEnd == "" || assetWarrantyEnd == '请选择保修结束时间')) {
							assetWarrantyStart = ""
							assetWarrantyEnd = ""
							// app.toast("请选择保修开始时间")
							// return
						} else {
							if (assetWarrantyEnd == undefined || assetWarrantyEnd == "" || assetWarrantyEnd == '请选择保修结束时间') {
								app.toast("请选择保修结束时间")
								return
							}
							if (assetWarrantyStart == undefined || assetWarrantyStart == "" || assetWarrantyStart == '请选择保修开始时间') {
								app.toast("请选择保修开始时间")
								return
							}
							if (stringYYYYMMDDHHMMToDate(assetWarrantyStart).getTime() > stringYYYYMMDDHHMMToDate(assetWarrantyEnd).getTime()) {
								app.toast("保修结束时间不能小于保修开始时间")
								return false
							}
						}


						var assetSn = h("#assetSn").val()
						ajaxPost(BASE_URL + "cc/installation/quality/report/addEquipmentAccessory", {
							"serviceNo": h("#serviceNoV").val(),
							"enginnerId": app.getUser().enginnerId,
							"accessoryName": assetName,
							"serialNumber": assetSn,
							"warrantyStartTime": assetWarrantyStart,
							"warrantyEndTime": assetWarrantyEnd,
							"instrumentNo": h("#instrumentNo").val()
						}, function(data) {
							console.log(JSON.stringify(data))
							if(data.code==200){
								app.toast("添加成功")
							}else{
								app.toast("添加失败")
							}
							if(self.addType === 1){
								var accessoryEquipmentList = plus.webview.getWebviewById('view/service/report/installationquality/accessoryEquipment/list.html');
								if(accessoryEquipmentList){
									accessoryEquipmentList.evalJS('initData()')
								}
								self.close()
							}else {
								$.back()
							}
						}, function(errorMsg) {
							console.log(JSON.stringify(errorMsg))
						});
						
						
					})

				});
			}(mui, document));
				
		</script>
		<!-- js代码 end -->
	</body>
</html>
